<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        :root {
            --column: 4;
        }

        .wrap {
            overflow: hidden;
        }

        .item {
            /* calc(100%/4)  calc(% - px)*/
            float: left;
            width: calc(100% / var(--column));
            height: 300px;
            margin-bottom: 20px;
        }

        .item:nth-of-type(2n+1) {
            background-color: rebeccapurple;
        }

        .item:nth-of-type(2n) {
            background-color: red;
        }

        /* <= 1080 适配pad端 */
        @media screen and (max-width: 1080px) {
            :root {
                --column: 2;
            }
        }

        /* <= 640 适配手机端 */
        @media screen and (max-width: 640px) {
            :root {
                --column: 1;
            }
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
        <div class="item"></div>
    </div>
</body>

</html>